##
# \file shoe.py
#

# --  Python imports  --
from random import shuffle
# -- End Python imports --

# --  Pybrain imports  --
# -- End Pybrain imports --

# --  Project imports  --
from namedcards import Cards
# -- End Project imports --

##
# \class Shoe
# \details This class represents the set of decks that the game is dealt from.
class Shoe:

    ##
    # \details Initializes a shoe with the specified number of decks.
    # \pre The default number of decks is six (6).
    # \post The new shoe is created within the instance of this class.
    # \param num_decks The number of decks to use to construct the shoe.
    # \return none
    def __init__(self, num_decks=6):
        self.shoe = []
        self.number_of_decks = num_decks
        self.generate(self.number_of_decks)

    ##
    # \details Creates a shoe with the specified number of decks.
    # \pre none
    # \post The new shoe is created within the instance of this class.
    # \param num_decks The number of decks to use to construct the shoe.
    # \return none
    def generate(self, num_decks):
        self.shoe = []
        for deck in range(0, num_decks):
            for suit in range(0, Cards.NUM_SUIT):
                # 1. Numerical Cards
                self.shoe.extend(range(Cards.TWO, Cards.ACE + 1))
                # 2. Face Cards
                self.shoe.extend([Cards.JACK, Cards.QUEEN, Cards.KING])
        shuffle(self.shoe)

    ##
    # \details Deals a card from the shoe.
    # \pre A shoe has been previously generated.
    # \post The shoe will have the dealt card removed from it.
    # \param none
    # \return The card that was dealt.
    def deal(self):
        # If the shoe is almost empty, reshuffle the entire shoe.
        if len(self.shoe) < 5:
            self.generate(self.number_of_decks)
        return self.shoe.pop()
